package com.ionehe.component;

import com.google.common.base.Preconditions;
import com.ionehe.enums.MessageType;
import com.ionehe.exception.MessageRunTimeException;
import com.ionehe.handler.MessageProducer;
import com.ionehe.handler.SendCallback;
import com.ionehe.model.api.Message;
import com.ionehe.domain.service.RabbitBroker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ProducerClient implements MessageProducer {
 
    @Autowired
    RabbitBroker rabbitBroker;
 
    @Override
    public void send(Message message) throws MessageRunTimeException {
        Preconditions.checkNotNull(message.getTopic());
        String messageType = message.getMessageType();
        switch (messageType){
            case MessageType.RAPID:
                rabbitBroker.rapidSend(message);
                break;
            case MessageType.CONFIRM:
                rabbitBroker.confirmSend(message);
                break;
            case MessageType.RELIANT:
                rabbitBroker.reliantSend(message);
                break;
            default:
                break;
        }
    }
 
    @Override
    public void send(Message message, SendCallback sendCallback) throws MessageRunTimeException {
 
    }
 
    @Override
    public void send(List<Message> messages) throws MessageRunTimeException {
 
    }
}